package com.xiaomi.baidumap.favorite.dao;

import com.j256.ormlite.dao.Dao;
import com.xiaomi.baidumap.favorite.model.RepoGroup;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by Administrator on 16-9-1.
 */
public class LocalRepoGroupDao {

    //主要是进行数据库的增添改查
    private Dao<RepoGroup,Long> dao;

    public LocalRepoGroupDao(DBHelper helper) {
        try {
             dao = helper.getDao(RepoGroup.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    //添加到数据库
    public void createOrUpdate(RepoGroup repos){
        try {
             dao.createOrUpdate(repos);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void createOrUpdate(List<RepoGroup> lists){
        for (RepoGroup repo:lists){
            createOrUpdate(repo);
        }
    }


    //查找所有的
    public List<RepoGroup> queryForAll(){
        try {
           return dao.queryForAll();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    //根据Id查找
    public RepoGroup queryId(long id){
        try {
          return dao.queryForId(id);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
